package top.swimmer.tools.data.linked;

public class Reverse {
    public static ListNode reverse(ListNode node) {
        if (node == null || node.next == null) {
            return node;
        }

        ListNode prev = null;
        ListNode current = node;

        while (current != null) {
            ListNode next = current.next;
            current.next = prev;
            prev = current;
            current = next;
        }
        return prev;
    }

    public static void main(String[] args) {
        System.out.println(reverse(ListNode.get()));
    }
}
